/**
 * List of {tblName} [tblTitle] .
 * Created by buzhizhe CodeConvert on {date}.
 */

var VM=new Object();
ApiHost += "/{subFolder}";

$(function(){
    initPage();
    loadData();
});

//初始化页面元素
function initPage() {
    VM = new Vue({
        delimiters: ["[[", "]]"],
        el: '#app',
        data: {model: []}
    });

}

//加载数据
function loadData() {
    var id=GetQueryString("id");
    var url = ApiHost + "/{tblName}view";
    $.ajax({
            type: "post",
            url: url,
            data: {
                id:id
            },
            dataType: "json",
            error: function (request) {
                ajaxError(request, $(this));
            },
            success: function (result) {
                ajaxSuccess(result, $(this));
                var code=result.statecode;
                if(code==0){
					VM.model = result.data;
                    dealData();
                }else{
                    layerAlert("获取失败："+result.message);
                }
            }
        }
    );

}

//处理数据
function dealData() {
	loadJson(VM.model);
}

//保存数据
function formAddSubmit() {
    var url = ApiHost + "/{tblName}add";
    var formData =$('#formadd').serialize();
    $.ajax({
            type: "post",
            url: url,
            data: formData,
            dataType: "json",
            error: function (request) {
                ajaxError(request, $(this));
            },
            success: function (result) {
                ajaxSuccess(result, $(this));
                var code=result.statecode;
                if(code==0){
                    //layerAlert("提交成功");
                    layerAlert("成功",function () {
                        parent.layerCallBack();
                        closeLayer();
                    })
                }else{
                    layerAlert("提交失败："+result.message);
                }
            }
        }
    );

}

//关闭当前layer窗口并更新父窗口数据
function closeThisLayer() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
    parent.layerCallBack();
}

